<layout name='layout' />
<html>
    <head>    
    <title>ThinkPHP示例：Ajax表单提交</title>
    <load type="css" href='__PUBLIC__/Css/common.css' />
    <load href="__PUBLIC__/Js/Jquery/jquery.form.js" />
    <load href="__PUBLIC__/jqueryui/ui/jquery-ui-1.8.21.custom.js" />
    <script language="JavaScript">
    <!--
	function messagebox(msg)
{
  $("#message-details").html(msg);
  $( "#dialog:ui-dialog" ).dialog( "destroy" );
  $( "#dialog-message" ).dialog({
    width: 360,
    height: 230,
    buttons: {
          确认: function() {
             $( this ).dialog( "close" );
      }
    }
  });
}
    $(function(){
		  $( "#dialog-message" ).hide();
		$( "#username" ).autocomplete({
			source: "__URL__/checkName",
			minLength: 1,
		});
        $('#form1').ajaxForm({
            beforeSubmit:  checkForm,  // pre-submit callback
            success:       complete,  // post-submit callback
            dataType: 'json'
        });
        function checkForm(){
            if( '' == $.trim($('#title').val())){
			
                $('#result').html('标题不能为空').show();
                return false;
            }
            //可以在此添加其它判断
        }
        function complete(data){
            if (data.status==1){
            	//$('#result').html(data.info).show();
                // 更新列表
                //var vo = data.data;
                //$('#result').html(vo.title+vo.username+vo.content).show();
                //var html =  data.title+data.username+data.data.content;
               messagebox(data.info);
            }else{
                //$('#result').html(data.info).show();
            	 messagebox(data.info);
            }
        }

    });
  
    //-->
    </script>
</head>

<div id="dialog-message" title="发送完成">
    <p>
        <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
        <span id="message-details"></span>
    </p>
</div>
    <div class="main">
       
        <form id="form1" method='post' action="__URL__/sendajax">
            <table cellpadding=2 cellspacing=2>
                <tr>
                    <td colspan="2"><div id="result" class="none result" style="font-family:微软雅黑,Tahoma;letter-spacing:2px"></div></td>
                </tr>
				 <tr>
                    <td colspan="2"><div id="list" class="none result" style="font-family:微软雅黑,Tahoma;letter-spacing:2px"></div></td>
                </tr>
                <tr>
                    <td class="tRight" >发送给：</td>
                    <td class="tLeft" ><input type="text" name="username" id="username" style="height:23px" class="huge bLeft" value="{$defultmail["getname"]}"></td>
                </tr>
                <tr>
                    <td class="tRight" width="12%">标题：</td>
                    <td class="tLeft" ><input type="text" name="title" id="title" style="height:23px" class="large bLeft" value="{$defultmail["title"]}"></td>
                </tr>
                
                <tr>
                    <td class="tRight tTop" >内容：</td>
                    <td><textarea name="content" id="content" class="huge bLeft" rows="8" cols="60"></textarea></td>
                </tr>
                <tr>
                    <td><input type="hidden" name="ajax" value="1"></td>
                    <td><input type="submit"  class="button" value="发送"> 
                </tr>
                <tr>
                    <td></td>
                    <td><hr></td>
                </tr>
            </table>
        </form>
      
    </div>